<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="/WEB-INF/faces/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <h:panelGroup id="table">
            <h:form>
                <p:dataTable var="course" value="#{adminCoursesBackingBean.courses}" id="courses">
                    <f:facet name="header">
                        Courses
                    </f:facet>
                    <p:column>
                        <f:facet name="header">
                            Name
                        </f:facet>
                        <h:inputHidden id="tblPid" value="#{course.id}" />
                        <h:outputText value="#{course.courseName}" id="name"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            Year
                        </f:facet>
                        <h:outputText value="#{course.yearNumber}" id="year"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            Teacher
                        </f:facet>
                        <h:outputText value="#{course.teacher.user.fname}" id="teacher"/>
                    </p:column>
                    <p:column>
                        <p:commandButton actionListener="#{adminCoursesControllerBean.removeCourse}" update="@form" value="Delete">
                            <f:attribute value="#{course}" name="course"/>
                        </p:commandButton>
                    </p:column>
                    <p:column>
                        <input type="button" value="Edit" class="editBtn" />
                    </p:column>
                </p:dataTable>
            </h:form>
        </h:panelGroup>
        <h:form>
            <h:inputHidden id="pkey" value="#{adminCoursesBackingBean.editId}" />
            <h:panelGrid columns="2">
                <h:outputLabel for="name" value="Name: " />
                <p:inputText id="formname" value="#{adminCoursesBackingBean.newCourse.courseName}" required="true"/>
                <h:outputLabel for="year" value="Year: " />
                <p:inputText id="formyear" value="#{adminCoursesBackingBean.newCourse.yearNumber}" required="true"/>
                <h:outputLabel for="formteacher" value="Teacher: " />
                <h:selectOneMenu id="formteacher" value="#{adminCoursesBackingBean.teacherId}">
                    <f:selectItems value="#{adminCoursesBackingBean.teachers}" var="t" itemLabel="#{t.user.fname}" itemValue="#{t.id}" />
                </h:selectOneMenu>
                <p:commandButton id="subBtn" actionListener="#{adminCoursesControllerBean.editAddCourse}" value="Add Course" update="table, @form"/>
                <p:messages />
            </h:panelGrid>
        </h:form>
    </ui:define>

</ui:composition>
